package com.tjk.crawler.service.system.service.imp;

import com.tjk.crawler.base.entity.Result;
import com.tjk.crawler.repository.system.user.dao.SysUserMapper;
import com.tjk.crawler.repository.system.user.entity.SysUser;
import com.tjk.crawler.repository.system.user.entity.query.SysUserQuery;
import com.tjk.crawler.service.system.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImp implements UserService {

    private final static Logger logger = LoggerFactory.getLogger(UserServiceImp.class);

    @Autowired
    private SysUserMapper sysUserMapper;


    @Override
    public Result isValidUser(String userName, String password) {
        SysUserQuery query = new SysUserQuery();
        query.setUserName(userName);
        List<SysUser> sysUsers = sysUserMapper.selectBySelective(query);
        if (sysUsers == null || sysUsers.isEmpty()) {
            return Result.fail("无该账号");
        }
        SysUser sysUser = sysUsers.get(0);
        if (sysUser.getStatus() == 0) {
            return Result.fail("该用户已停用");
        }
        if (!password.equals(sysUser.getPassword())) {
            return Result.fail("密码不正确");
        } else {
            return Result.success(sysUser);
        }
    }
}
